/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isil.tia.dao.jdbc;

import com.isil.tia.dao.AuditDao;
import com.isil.tia.domain.Audit;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author IVAN
 */
public class AuditDaoJdbc implements AuditDao {

    private JdbcTemplate jdbcTemplate;

    public void setDataSource(DataSource dataSource) {
        jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public void saveAudit(Audit audit) {
        jdbcTemplate.update("insert into audit(operation,query,user_id,audit_date) values(?,?,?,?)",
                audit.getOperation(), audit.getQuery(), audit.getUser_id(), audit.getAudit_date());
    }

    public List<Audit> getAllAudits() {
        BeanPropertyRowMapper<Audit> beanPropertyRowMapper = new BeanPropertyRowMapper<Audit>(Audit.class);
        return jdbcTemplate.query("select audit_id, operation, query, user_id, audit_date from audit", beanPropertyRowMapper);
    }
}
